package demo1224.pm;

import java.io.*;

/*
转换流:
InputStreamReader是字节流通向字符流的桥梁.
1.public InputStreamReader(InputStream in);
使用默认的字符集创建一个InputStreamReader对象

2.public InputStreamReader(InputStream in,String charset);
使用指定的字符集创建一个InputStreamReader对象.

成员方法:
1.public int read() throws IOException 读取单个字符
2.public int read(char [] cs);
把读取到的字符存放到字符数组中.


OutputStreamWriter 是字符流通向字节流的桥梁;
public OutputStreamWriter(OutputStream out)
使用默认的字符集创建一个OutputStreamWriter对象.

public OutputStreamWriter(OutputStream out,String charsetName)
                   throws UnsupportedEncodingException
使用指定的字符集创建一个OutputStreamWriter对象.
成员方法:
public void write(int c);写入字符到输出流中
public void write(char[] cs);把字符数组中字符写入到输出流中.
public void flush();把输出流中的数据刷新到硬盘中.
public void close();关闭资源.
 */
public class Demo_07 {
    public static void main(String[] args) {
        try (InputStreamReader is = new InputStreamReader
                (new FileInputStream("a.txt"))
             ; OutputStreamWriter os = new OutputStreamWriter
                (new FileOutputStream("aa.txt"))) {

            int read;
            while ((read = is.read())!=-1){
               os.write(read);
            }
            os.flush();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
